https://github.com/nericode/nativescript-mercadopago-px
Mercado Pago's Official Android | iOS checkout library
https://github.com/nericode/nativescript-mercadopago-px
Last synced: 10 months ago
JSON representation
Mercado Pago's Official Android | iOS checkout library
- Host: GitHub
- URL: https://github.com/nericode/nativescript-mercadopago-px
- Owner: nericode
- License: apache-2.0
- Created: 2019-06-23T00:24:13.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T01:29:32.000Z (over 3 years ago)
- Last Synced: 2025-07-26T18:40:06.980Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 3.53 MB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mercadopago-px  
Integration with [Mercado Pago checkout](https://www.mercadopago.com.ar/developers/es/guides/payments/web-payment-checkout/introduction/)
## Support
Support Android & iOS.
## Installation
```javascript
tns plugin add nativescript-mercadopago-px
```
## Usage
```javascript
this.mercadopagoPx
.start({
language: "es",
publicKey: "PUBLIC_KEY",
preferenceId: "PREFERENCE_ID" // Get custom preference_if of side server.
})
.then(result => {
// Success payment
})
.catch(error => {
// Cancel payment or Error payment
});
```
### Vue
```vue
```
```javascript
import { MercadopagoPx } from "nativescript-mercadopago-px";
export default {
data() {
return {
accessToken: "TEST-8479223465824183-062120-902fb3cb694af3cff10eb7271dbea60f-588489468",
preferenceId: "",
}
},
methods: {
generatePreference(){
fetch("https://api.mercadolibre.com/checkout/preferences?access_token="+this.accessToken, {
method: 'POST',
headers:{
'Content-Type': 'application/json',
'cache-control': 'no-cache'
},
body: JSON.stringify({
"items": [
{
"id": "12345",
"title": "My product",
"currency_id": "ARS", // Required field
"picture_url": "https://www.mercadopago.com/org-img/MP3/home/logomp3.gif",
"description": "Description of my product",
"category_id": "art",
"quantity": 1,
"unit_price": 100
}
],
"payer": {
"email": "test_user_6523408@testuser.com", // Required field
},
})
})
.then(response => {
response.json()
.then(resp => this.preferenceId = resp.id) // Save the preference to use it at checkout
})
.catch(error => console.log("Failed to generate preference",error))
},
checkout() {
var mercadopagoPx = new MercadopagoPx();
mercadopagoPx.checkout({
language: "es",
publicKey: "TEST-ebe497d7-3b86-4728-8f87-e5010231c8a0",
preferenceId: this.preferenceId
})
.then(paymentInfo => console.log("Success payment =>", paymentInfo))
.catch(error => console.log("Cancel payment or Error payment =>", error));
},
}
}
```
#### iOS
If you want to use the plugin with Angular or Vue + Javascript in iOS, you must add the following in your `app.js` or `main.js`
### Angular
```javascript
import * as app from "tns-core-modules/application";
declare var UIResponder,
UIApplicationDelegate;
if (app.ios) {
var appDelegate = UIResponder.extend(
{
get window() {
return this._window;
},
set window(aWindow) {
this._window = aWindow;
},
},
{
protocols: [UIApplicationDelegate],
}
);
app.ios.delegate = appDelegate;
}
...
platformNativeScriptDynamic().bootstrapModule(AppModule);
```
### Vue
```javascript
const application = require("tns-core-modules/application");
if (application.ios) {
const MyDelegate = (function (_super) {
__extends(MyDelegate, _super);
function MyDelegate() {
_super.apply(this, arguments);
}
MyDelegate = UIResponder.extend(
{
get window() {
return this._window;
},
set window(aWindow) {
this._window = aWindow;
},
},
{
protocols: [UIApplicationDelegate],
}
);
MyDelegate.ObjCProtocols = [UIApplicationDelegate];
return MyDelegate;
})(UIResponder);
application.ios.delegate = MyDelegate;
}
```
## License
Apache License Version 2.0, January 2004