将RozorPay付款集成到Angular Project中

时间:2019-02-09 13:14:24

标签: angular typescript angular5 angular6

我正在Angular 7上尝试集成使用 RozorPay

我正在尝试使用Java Script进行集成,该脚本可在我的其他项目中使用,但是在Angular Project中使用相同的代码时会遇到问题

我在这里共享我的代码

html

200个硬币 500金币 1,000个硬币

TS

import { Component } from '@angular/core';
import * as $ from 'jquery';


@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'PaymentIntegration';




  // Use loadScript to load the Razorpay checkout.js
// -----------------------------------------------
var callRazorPayScript = function(itemId, amount, qty, processorId) {
  var merchangeName = "Merchant Name",
      img = "https://s3.amazonaws.com/uifaces/faces/twitter/jsa/128.jpg",
      name = "Harshil Hill",
      description = "Purchase Description",
      amount = amount,
      qty = qty;

  loadExternalScript('https://checkout.razorpay.com/v1/checkout.js').then(function() {
    var options = {
      key: 'rzp_live_ILgsfZCZoFIKMb',
      protocol: 'https',
      hostname: 'api.razorpay.com',
      amount: amount,
      name: merchangeName,
      description: description,
      image: img,
      prefill: {
        name: name,
      },
      theme: {
        color: '#b9a76e'
      },
      handler: function (transaction, response){
        console.log('Tshirt\\ntransaction id: ' + transaction.razorpay_payment_id);
        console.log(response.razorpay_payment_id)
      }
    };

    window.rzpay = new Razorpay(options);

        console.log('Item Id: ', amount);
    console.log('Amount: ', amount);
    console.log('Quantity: ', qty);
    console.log('Processor Id: ', processorId);

    rzpay.open();
  });
}

// Trigger call to action buttons depending on the bundle packs
// -----------------------------------------------
var $payBundle = $('.js-pay-bundle');

$payBundle.on('click', function() {
    var itemId = $(this).data('itemid'),
            amount = $(this).data('amount'),
            processorid = $(this).data('processorid'),
            qty = $(this).data('qty');

    callRazorPayScript(itemId, amount, processorid, qty);
});
}

我遇到很多错误,可能是因为我的typeScript在JavaScript类型中转换得不好

0 个答案:

没有答案