Created
August 31, 2017 13:48
-
-
Save annibuliful/3a65a9d67a1e45835e24e19eb54b86b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buy(productID: String, productName: String, productPrices: any , productImage:any) { | |
this.sending = true; | |
this.resultPrice = this.productQuanity * productPrices; | |
let header = new Headers(); | |
header.append("Authorization", 'Basic cGtleV90ZXN0XzU3dm84OGhyeHpjcHp1aHp6cmc6'); | |
this.http.post('https://vault.omise.co/tokens', { | |
card: { | |
"name": this.name, | |
"number": this.number, | |
"expiration_month": this.expiration_month, | |
"expiration_year": this.expiration_year, | |
"security_code": this.security_code, | |
} | |
}, { | |
headers: header | |
}).subscribe((data) => { | |
let tokenID = data.json(); | |
this.apollo.mutate({ | |
mutation: this.payProductMutation, variables: { | |
products: { | |
productID: productID, | |
productNames: productName, | |
quantitys: this.productQuanity, | |
productPrices: productPrices, | |
price: this.resultPrice, | |
productImage: productImage | |
}, | |
tokenID: tokenID.id, | |
userID: localStorage.getItem('userID') | |
} | |
}).subscribe(({data , loading}) => { | |
let returnData: any = data; | |
console.log(data); | |
if(returnData.buyProduct.created == true){ | |
this.router.navigate(['paidsuccess']); | |
}else{ | |
this.error = "เกิดปัญหาในการชำระ" | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment